// 引入: mockjs 模块;
import Mock from 'mockjs'

function createUserList() {
    return [
        {
            userId: 1,
            avatar:
                'https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif',
            username: 'admin',
            password: '111111',
            desc: '平台管理员',
            buttons: ['cuser.detail'],
            roles: ['admin'],
            token: 'Admin Token',
        },
        {
            userId: 2,
            avatar:
                'https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif',
            username: 'system',
            password: '111111',
            desc: '系统管理员',
            buttons: ['cuser.detail', 'cuser.user'],
            roles: ['admin'],
            token: 'System Token',
        },
    ]
}

export default [
	{
	  url: '/api/account/info',
	  method: 'GET',
	  response: () => {
		  const checkUser = createUserList().find(
		      (item) =>item.username === 'admin'
		  )
		 return{ code: 200, data:  checkUser ,message:'登录成功'}
	  },
	},
  {
    url: '/api/account/login',
    method: 'POST',
    response: ({ query }) => {
				const {username,password} = query
				//调用获取用户信息函数,用于判断是否有此用户
                 const checkUser = createUserList().find(
                     (item) =>item.username === username && item.password === password
                 )
                 //没有用户返回失败信息
                 if (!checkUser) {
                     return { code: 201, data: { message: '账号或者密码不正确' } }
                 }
                 //如果有返回成功信息
                 const { token } = checkUser
                 return { code: 200, data: { token } ,message:'登录成功'}
    },
  },
  
  {
    url: '/api/account/getMenuList',
    method: 'GET',
    response: ({ query }) => {
		const menulist = [{
				path: '/system',
				component: 'Layout',
				redirect: '/system/users',
				hidden:false,
				name: 'System',
				meta: {
					title: '系统管理',
					icon: 'HomeFilled',
					roles: ['admin', 'user:*']
				},
				children: [{
						path: '/system/users',
						component: '/system/UserView',
						name: 'Users',
						hidden:false,
						meta: {
							title: '用户管理',
							icon: 'user',
							roles: ['admin']
						}
					},
					{
						path: '/system/roles',
						component: '/system/RolesView',
						name: 'Roles',
						hidden:false,
						meta: {
							title: '角色管理',
							icon: 'Lock',
							roles: ['admin']
					 },
					},
					{
							path: '/system/permissions',
							component: '/system/PermissionsView',
							name: 'Permissions',
							hidden:false,
							meta: {
								title: '权限管理',
								icon:'Magnet',
								roles: ['admin']
							}
					},
				]
			},
			{
				path:'/job',
				name:'Job',
				redirect:'/job/list',
				component: 'Layout',
				hidden:false,
				meta:{
					title:'职位管理',
					icon:'Mouse',
					roles: ['admin']
				},
				children:[
					{
						path:'/job/list',
						name:'List',
						component:'/job/JobView',
						hidden:false,
						meta:{
							title:'职位列表',
							icon:'Printer',
							roles: ['admin']
						}
					}
				]
			}
	]
  	 return {code:200,message:'查询列表成功',data:menulist}
    },
  },
]